home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr47 / lzpip103.zip / LZWBITS.H < prev    next >
Text File  |  1980-08-19  |  4KB  |  165 lines

  1. /* lzwbits.h */
  2.  
  3. /* Set USERMEM to the maximum amount of physical user memory available
  4.  * in bytes.  USERMEM is used to determine the maximum BITS that can be used
  5.  * for compression.
  6.  *
  7.  * SACREDMEM is the amount of physical memory saved for others; compress
  8.  * will hog the rest.
  9.  */
  10. #ifndef SACREDMEM
  11. # define SACREDMEM 0
  12. #endif
  13.  
  14. #ifndef USERMEM
  15. # define USERMEM 450000L /* default user memory */
  16. #endif
  17.  
  18. #ifdef pdp11
  19. # define BITS    12    /* max bits/code for 16-bit machine */
  20. # define NO_UCHAR    /* also if "unsigned char" functions as signed char */
  21. # undef USERMEM        /* don't forget to compile with -i */
  22. #endif
  23.  
  24. #ifdef z8000
  25. # define BITS 12
  26. # undef vax    /* weird preprocessor */
  27. # undef USERMEM
  28. #endif
  29.  
  30. #ifdef __TURBOC__
  31. # ifndef MSDOS
  32. #  define MSDOS
  33. # endif
  34. #endif
  35.  
  36. #ifdef MSDOS
  37. # define BIG
  38. # undef USERMEM
  39. # ifdef BIG        /* then this is a large data compilation */
  40. #  define BITS     16
  41. #  define XENIX_16
  42. # else            /* this is a small model compilation */
  43. #  define BITS     12
  44. # endif
  45. #else
  46. #undef BIG
  47. #endif
  48.  
  49. #ifdef pcxt
  50. # define BITS    12
  51. # undef USERMEM
  52. #endif
  53.  
  54. #ifdef USERMEM
  55. # if USERMEM >= (433484L+SACREDMEM)
  56. #  define PBITS 16
  57. # else
  58. #  if USERMEM >= (229600L+SACREDMEM)
  59. #   define PBITS    15
  60. #  else
  61. #   if USERMEM >= (127536L+SACREDMEM)
  62. #    define PBITS    14
  63. #   else
  64. #    if USERMEM >= (73464L+SACREDMEM)
  65. #     define PBITS    13
  66. #    else
  67. #     define PBITS    12
  68. #    endif
  69. #   endif
  70. #  endif
  71. # endif
  72. # undef USERMEM
  73. #endif
  74.  
  75. #ifdef PBITS
  76. # ifndef BITS
  77. #  define BITS PBITS /* Preferred BITS for this memory size */
  78. # endif
  79. #endif
  80.  
  81. #ifdef M_XENIX
  82. # ifndef i386
  83. #  if BITS == 16    /* Stupid compiler can't handle arrays with */
  84. #   define XENIX_16    /* more than 65535 bytes - so we fake it */
  85. #  else
  86. #   if BITS > 13    /* Code only handles BITS = 12, 13, or 16 */
  87. #    define BITS 13
  88. #   endif
  89. #  endif
  90. # endif
  91. #endif
  92.  
  93. /* signed compare is slower than unsigned (Perkin-Elmer) */
  94. #ifdef interdata
  95. #    define SIGNED_COMPARE_SLOW
  96. #endif
  97. #ifdef SIGNED_COMPARE_SLOW
  98. #    define to_compare(x) (unsigned)(x)
  99. #else
  100. #    define to_compare(x) (x)
  101. #endif
  102.  
  103. #if BITS == 16
  104. # define _HSIZE    69001L    /* 95% occupancy */
  105. #endif
  106. #if BITS == 15
  107. # define _HSIZE    35023L    /* 94% occupancy */
  108. #endif
  109. #if BITS == 14
  110. # define _HSIZE    18013L    /* 91% occupancy */
  111. #endif
  112. #if BITS == 13
  113. # define _HSIZE    9001L    /* 91% occupancy */
  114. #endif
  115. #if BITS <= 12
  116. # define _HSIZE    5003L    /* 80% occupancy */
  117. #endif
  118.  
  119. /* a code_int must be able to hold 2**BITS values of type int, and also -1 */
  120. #if BITS > 15
  121. #    define code_int long
  122. #else
  123. #    define code_int int
  124. #endif
  125.  
  126. #ifdef SIGNED_COMPARE_SLOW
  127. #    define count_int unsigned long
  128. #else
  129. #    define count_int long
  130. #endif
  131.  
  132. #ifdef NO_UCHAR
  133. #    define char_type char
  134. #    define char_to_byte(x) ((x) & 0xff)
  135. #else
  136. #    define char_type unsigned char
  137. #    define char_to_byte(x) (x)
  138. #endif
  139.  
  140. /* Magic header bytes */
  141. #define LZW_0TH_MAGIC 0x1f
  142. #define LZW_1ST_MAGIC 0x9d
  143. /* Defines for third byte of header */
  144. /* Masks 0x40 and 0x20 are reserved for future. */
  145. #define BIT_MASK   0x1f
  146. #define BLOCK_MASK 0x80
  147. #define INIT_BITS 9 /* initial number of bits/code */
  148.  
  149. #define MAXCODE(n_bits)    (((code_int) 1 << (n_bits)) - 1)
  150.  
  151. #ifdef XENIX_16
  152. #    define PAGEXP   13
  153. #    define PAGESIZE (1<<PAGEXP)
  154. #    define PAGEMASK (PAGESIZE-1)
  155. #    define MAXPAGES (int)((_HSIZE+PAGESIZE-1)/PAGESIZE)
  156. #    define NUMPAGES (int)((((code_int)1 << BITS) + PAGESIZE-1)/PAGESIZE)
  157. #endif
  158.  
  159. #define CHECK_GAP 10000 /* ratio check interval */
  160.  
  161. /* the next two codes should not be changed lightly, as they */
  162. /* must not lie within the contiguous general code space.    */
  163. #define FIRST    257    /* first free entry */
  164. #define CLEAR    256    /* table clear output code */
  165.